<template>
  <div class="app-container">
    <slot :list_type="list_type"></slot>
    <div class="filter-container">
      <selectServer @server-selected="handleSelectServer" />
      <el-date-picker v-model="searchForm.date" class="filter-item" type="date" style="width: 160px;" placeholder="时间"></el-date-picker>
      <!-- <el-input v-model="searchForm.hero_id" class="filter-item" style="width: 150px;" placeholder="英雄ID" /> -->
      <el-button class="filter-item" type="primary" plain icon="el-icon-search" @click="handleFilter">搜索</el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" :style="{height: '780px'}" class="mt-10" border height="780">
      <el-table-column label="英雄" prop="hero_name" width="150px" align="center"></el-table-column>
      <el-table-column label="总拥有人数" prop="num" width="150px" align="center"></el-table-column>
      <template v-if="columns">
        <el-table-column
          v-for="column in columns"
          :key="column.prop"
          :label="column.label"
          :prop="column.prop"
          :width="column.width"
          :align="column.align || 'center'"
        />
      </template>
    </el-table>
  </div>
</template>

<script>
import { getActorHeroList } from '@/api/statis'
import checkPermission from '@/utils/permission'
import SelectServer from '@/components/SelectServer'
export default {
  name: 'Hero',
  components: { SelectServer },
  props: {
    list_type: { type: Number, default: 0 }
  },
  data() {
    return {
      permissionRoles: this.$store.state.user.permissionRoles,
      list: [],
      serverList: [],
      loading: false,
      listLoading: false,
      columns: [],
      downloadLoading: false,
      searchForm: {
        date: new Date(Date.now() - 86400000 * 1),
        sid: [],
        hero_id: ''
      }
    }
  },
  computed: {
  },
  mounted() {
    console.log('Received list_type:', this.list_type) // 检查接收到的 prop 是否正确
  },
  created() {
    // this.getList()
  },
  methods: {
    checkPermission,
    handleFilter() {
      this.getList()
    },
    handleSelectServer(servers) {
      this.searchForm.servers = servers
    },
    handleChange(val) {
      // this.type = this.types[val]
    },
    getTypes() {
      const query = Object.assign({ day_type: this.list_type }, this.searchForm)
      return query
    },
    async getList() {
      this.listLoading = true
      const res = await getActorHeroList(Object.assign({}, this.getTypes()))
      this.listLoading = false
      this.list = res.data.items
      this.columns = []
      const mapList = res.data['maps']
      for (const data_1 in mapList) {
        this.columns.push({
          prop: `${data_1}`,
          label: mapList[data_1],
          width: '100px',
          align: 'center'
        })
      }
    },
    handleDownload() {
      this.downloadLoading = true
    },
    formatJson(filterVal) {
      return this.list.map(v => filterVal.map(j => {
        return v[j]
      }))
    }
  }
}
</script>
